<template>
	<view class="container">
		<view class="box-bg">
			<uni-nav-bar>
				<block slot="left">
					<view class="city" @click="chooseAddress">
						<view>
							<text class="uni-nav-bar-text">{{ city }}</text>
						</view>
						<uni-icons type="arrowdown" color="#666" size="18" />
					</view>
				</block>
				<view class="input-view">
					<uni-icons class="input-uni-icon" type="search" size="18" color="#999" />
					<input confirm-type="search" class="nav-bar-input" type="text" placeholder="输入搜索关键词"
						@confirm="confirm" />
				</view>
				<block slot="right">
					<view class="city">
						搜索
					</view>
				</block>
			</uni-nav-bar>
		</view>
		<!-- 页面调用 -->
		<ju-navigator-grid element-id="navigatorMenu" :list="menu" @press="onPress" height="180" size="90" />
		<view style="width: 100%;margin: 20rpx auto;">
			<u-swiper :list="list3" height="350rpx" indicator indicatorActiveColor="#ffd100" indicatorMode="line"
				circular></u-swiper>
		</view>
		<shopItem :shopList="shopList" @toDetail="toShopDetail"></shopItem>
		<view style="padding: 5rpx 0;">
			<u-loadmore :status="loadMoreStatus"></u-loadmore>
		</view>
		<u-loading-page loading-mode="semicircle" :loading="showLoading"></u-loading-page>
	</view>

</template>

<script>
	import config from '@/config.js'
	import {
		buyProductApi,
		getGoodsListApi,
		getBigClassApi,
		getShopListApi
	} from '@/api/index.js'
	import navBar from "@/components/lz-navBar/navBar.vue"
	import shopItem from "@/components/goods-item/index.vue"
	export default {
		components: {
			navBar,
			shopItem
		},
		data() {
			return {
				showLoading: true,
				pageFlag: false,
				loadMoreStatus: 'nomore',
				imgBaseurl: config.appInfo.imgBaseurl,
				city: '石家庄',
				menu: [{
						title: "炒菜",
						url: '/pages/shopClassDetail/index',
						icon: "/static/logo.png"
					},
					{
						title: "饺子",
						url: '/pages/shopClassDetail/index',
						icon: "/static/logo.png"
					},
					{
						title: "面条",
						url: '/pages/shopClassDetail/index',
						icon: "/static/logo.png"
					},
					{
						title: "包子",
						url: '/pages/shopClassDetail/index',
						icon: "/static/logo.png"
					},
					{
						title: "螺蛳粉",
						url: '/pages/shopClassDetail/index',
						icon: "/static/logo.png"
					},
					{
						title: "麻辣唐",
						url: '/pages/shopClassDetail/index',
						icon: "/static/logo.png"
					},
					{
						title: "铁板饭",
						url: '/pages/shopClassDetail/index',
						icon: "/static/logo.png"
					},
					{
						title: "炸串",
						url: '/pages/shopClassDetail/index',
						icon: "/static/logo.png"
					},
					{
						title: "炸鸡汉堡",
						url: '/pages/shopClassDetail/index',
						icon: "/static/logo.png"
					},
					{
						title: "卷饼",
						url: '/pages/shopClassDetail/index',
						icon: "/static/logo.png"
					}
				],
				list3: [
					'https://cdn.uviewui.com/uview/swiper/swiper3.png',
					'https://cdn.uviewui.com/uview/swiper/swiper2.png',
					'https://cdn.uviewui.com/uview/swiper/swiper1.png',
				],
				shopList: [],
				page: 1
			}
		},
		onLoad() {
			this.getBigClass()
			this.getShopList()
		},
		computed: {


		},
		methods: {
			// 顶部商品大类
			async getBigClass() {
				const {
					data: res
				} = await getBigClassApi({})
				console.log(res);
				const newClass = res.all.map((item) => ({
					title: item.name,
					icon: this.imgBaseurl + item.images,
					id: item.id
				}))
				this.menu = newClass
			},
			// 选择地址
			chooseAddress() {
				uni.navigateTo({
					url: '/pages/chooseAddress/index'
				})
			},
			// 点击菜单事件
			onPress(e) {
				console.log(e)
				uni.navigateTo({
					url: '/pages/shopClassDetail/index?class=' + e.id
				})
			},
			// 跳转店铺详情
			toShopDetail(id) {
				uni.navigateTo({
					url: '/pages/shopDetail/index?id=' + id
				})
			},
			// 商家列表
			async getShopList(next) {
				this.loadMoreStatus = 'loading'
				try {
					const {
						data: res
					} = await getShopListApi({
						page: this.page
					});
					const shopList = res.Business
					if (shopList) {
						const newOrderList = next ?
							this.shopList.concat(shopList) :
							shopList
						this.shopList = newOrderList
					}
					this.showLoading = false;
					this.loadMoreStatus = 'nomore'
				} catch (e) {}
			},
		},
		// 触底分页
		onReachBottom() {
			if (!this.pageFlag) {
				this.page = this.page + 1
				this.getShopList(true);
			}
		},
	}
</script>

<style lang="scss">
	.container {
		width: 95%;
		margin: 0 auto;
	}

	$nav-height: 30px;

	.box-bg {
		background-color: #F5F5F5;
		padding: 5px 0;
	}

	.city {
		/* #ifndef APP-PLUS-NVUE */
		display: flex;
		/* #endif */
		flex-direction: row;
		align-items: center;
		justify-content: flex-start;
		// width: 160rpx;
		margin-left: 4px;
	}

	.input-view {
		/* #ifndef APP-PLUS-NVUE */
		display: flex;
		/* #endif */
		flex-direction: row;
		// width: 500rpx;
		flex: 1;
		background-color: #f8f8f8;
		height: $nav-height;
		border-radius: 15px;
		padding: 0 15px;
		flex-wrap: nowrap;
		margin: 7px 0;
		line-height: $nav-height;
	}

	.input-uni-icon {
		line-height: $nav-height;
	}

	.nav-bar-input {
		height: $nav-height;
		line-height: $nav-height;
		/* #ifdef APP-PLUS-NVUE */
		width: 370rpx;
		/* #endif */
		padding: 0 5px;
		font-size: 12px;
		background-color: #f8f8f8;
	}
</style>